<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:sys="clr-namespace:System;assembly=mscorlib"
                    xmlns:cmp="clr-namespace:Citrix.Cmp;assembly=Citrix.Cmp.Wpf">

  <!--=========================================================================================-->
  <!-- These scroll bar resources reconfigure the default scroll bar and scroll viewer
  appearance to give you thin, mobile style scroll bars. Since the scroll bars are too thin to
  use normally (by clicking on them), the styles also enable the kinetic touch scrolling from
  the Citrix Mobile Application SDK. -->

  <!-- Misc constants consumed in the scrollbar template/style definition. -->
  <sys:Double x:Key="ScrollbarWidth">4</sys:Double>
  <GridLength x:Key="ScrollbarWidthAsGridLength">4</GridLength>
  <CornerRadius x:Key="ScrollbarSliderCornerRadius">2</CornerRadius>
  <SolidColorBrush x:Key="ScrollbarBackgroundBrush">#00000000</SolidColorBrush>
  <SolidColorBrush x:Key="ScrollbarSliderBrush">#88000000</SolidColorBrush>

  <!-- Style for the slider in a scrollbar. -->
  <Style x:Key="ScrollBarThumb" TargetType="{x:Type Thumb}">
    <Setter Property="IsTabStop" Value="false"/>
    <Setter Property="Focusable" Value="false"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Thumb}">
          <Border x:Name="Border"
                    CornerRadius="{DynamicResource ScrollbarSliderCornerRadius}"
                    Background="{DynamicResource ScrollbarSliderBrush}">
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!-- Above and below the slider is the "background" of the scrollbar. You can click on this
    background to trigger per-page scrolling. This background is in fact one of these buttons. We
    display one of these transparent buttons above and below the slider to get the per-page
    scrolling behaviour when this area is clicked. -->
  <Style x:Key="ScrollBarPageButton" TargetType="{x:Type RepeatButton}">
    <Setter Property="IsTabStop" Value="false"/>
    <Setter Property="Focusable" Value="false"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type RepeatButton}">
          <Border Background="Transparent" />
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!-- This style sets our custom scroll bar as the default scroll bar style for the entire
    application. -->
  <Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
    <Setter Property="OverridesDefaultStyle" Value="true"/>
    <Setter Property="Width" Value="{DynamicResource ScrollbarWidth}"/>
    <Setter Property="MinWidth" Value="{DynamicResource ScrollbarWidth}"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ScrollBar}">
          <Grid>
            <Border CornerRadius="{DynamicResource ScrollbarSliderCornerRadius}"
                      Background="{DynamicResource ScrollbarBackgroundBrush}" />
            <Track Name="PART_Track" IsDirectionReversed="true">
              <Track.DecreaseRepeatButton>
                <RepeatButton Style="{DynamicResource ScrollBarPageButton}"/>
              </Track.DecreaseRepeatButton>
              <Track.Thumb>
                <Thumb Style="{DynamicResource ScrollBarThumb}" />
              </Track.Thumb>
              <Track.IncreaseRepeatButton>
                <RepeatButton Style="{DynamicResource ScrollBarPageButton}"/>
              </Track.IncreaseRepeatButton>
            </Track>
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
    <Style.Triggers>
      <Trigger Property="Orientation" Value="Horizontal">
        <Setter Property="Width" Value="Auto"/>
        <Setter Property="MinWidth" Value="0"/>
        <Setter Property="Height" Value="{DynamicResource ScrollbarWidth}"/>
        <Setter Property="MinHeight" Value="{DynamicResource ScrollbarWidth}"/>
        <Setter Property="Template">
          <Setter.Value>
            <ControlTemplate TargetType="{x:Type ScrollBar}">
              <Grid>
                <Border CornerRadius="{DynamicResource ScrollbarSliderCornerRadius}"
                          Background="{DynamicResource ScrollbarBackgroundBrush}" />
                <Track Name="PART_Track" IsDirectionReversed="false">
                  <Track.DecreaseRepeatButton>
                    <RepeatButton Style="{DynamicResource ScrollBarPageButton}"/>
                  </Track.DecreaseRepeatButton>
                  <Track.Thumb>
                    <Thumb Style="{DynamicResource ScrollBarThumb}" />
                  </Track.Thumb>
                  <Track.IncreaseRepeatButton>
                    <RepeatButton Style="{DynamicResource ScrollBarPageButton}"/>
                  </Track.IncreaseRepeatButton>
                </Track>
              </Grid>
            </ControlTemplate>
          </Setter.Value>
        </Setter>
      </Trigger>
    </Style.Triggers>
  </Style>

  <SolidColorBrush x:Key="PageScrollStrokeBrush" Color="#FFEEEEEE"/>

  <!-- Page scroll button path styles. -->
  <Style x:Key="UpArrowStyle" TargetType="{x:Type Path}">
    <Setter Property="Data" Value="M0,20 L20,0 40,20 32,20 32,40 8,40 8,20 z"/>
    <Setter Property="Fill" Value="Transparent"/>
    <Setter Property="Stroke" Value="{StaticResource PageScrollStrokeBrush}"/>
    <Setter Property="Effect">
      <Setter.Value>
        <DropShadowEffect BlurRadius="2" Color="#FFDEDEDE" ShadowDepth="1"/>
      </Setter.Value>
    </Setter>
  </Style>
  <Style x:Key="RightArrowStyle" TargetType="{x:Type Path}" BasedOn="{StaticResource UpArrowStyle}">
    <Setter Property="Effect">
      <Setter.Value>
        <DropShadowEffect BlurRadius="2" Color="#FFDEDEDE" ShadowDepth="1" Direction="90"/>
      </Setter.Value>
    </Setter>
    <Setter Property="LayoutTransform">
      <Setter.Value>
        <RotateTransform Angle="90"/>
      </Setter.Value>
    </Setter>
  </Style>
  <Style x:Key="DownArrowStyle" TargetType="{x:Type Path}">
    <Setter Property="Data" Value="M8,0 L32,0 32,20 40,20 20,40 0,20 8,20 z"/>
    <Setter Property="Fill" Value="Transparent"/>
    <Setter Property="Stroke" Value="{StaticResource PageScrollStrokeBrush}"/>
    <Setter Property="Effect">
      <Setter.Value>
        <DropShadowEffect BlurRadius="2" Color="#FFDEDEDE" ShadowDepth="1"/>
      </Setter.Value>
    </Setter>
  </Style>
  <Style x:Key="LeftArrowStyle" TargetType="{x:Type Path}" BasedOn="{StaticResource DownArrowStyle}">
    <Setter Property="Effect">
      <Setter.Value>
        <DropShadowEffect BlurRadius="2" Color="#FFDEDEDE" ShadowDepth="1" Direction="90"/>
      </Setter.Value>
    </Setter>
    <Setter Property="LayoutTransform">
      <Setter.Value>
        <RotateTransform Angle="90"/>
      </Setter.Value>
    </Setter>
  </Style>

  <!--=========================================================================================-->
  <!-- Custom scroll viewer that overlays the the scroll bars over the content to save on
    space. -->
  <Style x:Key="{x:Type ScrollViewer}" TargetType="{x:Type ScrollViewer}">
    <Setter Property="OverridesDefaultStyle" Value="True" />
    <Setter Property="cmp:KineticScrollingBehaviour.HandleKineticScrolling" Value="True"/>
    <Setter Property="cmp:KineticScrollingBehaviour.Friction" Value="0.92"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ScrollViewer}">
          <Grid>

            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*"/>
              <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
              <RowDefinition Height="*"/>
              <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <ScrollContentPresenter x:Name="PART_ScrollContentPresenter"
                                      Grid.Column="0" Grid.Row="0"
                                      Grid.ColumnSpan="2" Grid.RowSpan="2"
                                      Margin="{TemplateBinding Padding}" 
                                      Content="{TemplateBinding Content}"
                                      ContentTemplate="{TemplateBinding ContentTemplate}"
                                      CanContentScroll="{TemplateBinding CanContentScroll}"
                                      CanHorizontallyScroll="False" CanVerticallyScroll="False"/>
            <ScrollBar Orientation="Vertical" Grid.Row="0" Grid.Column="1"
                         Cursor="Arrow"
                         Maximum="{TemplateBinding ScrollableHeight}" Minimum="0"
                         Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
                         ViewportSize="{TemplateBinding ViewportHeight}"
                         Name="PART_VerticalScrollBar"
                         Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                         AutomationProperties.AutomationId="VerticalScrollBar"/>
            <ScrollBar Orientation="Horizontal" Grid.Row="1" Grid.Column="0"
                         Cursor="Arrow"
                         Maximum="{TemplateBinding ScrollableWidth}" Minimum="0"
                         Value="{Binding HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
                         ViewportSize="{TemplateBinding ViewportWidth}"
                         Name="PART_HorizontalScrollBar"
                         Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
                         AutomationProperties.AutomationId="HorizontalScrollBar"/>

            <!-- Page scroll buttons. -->
            <Grid HorizontalAlignment="Right" VerticalAlignment="Bottom">
              <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
              </Grid.RowDefinitions>

              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
              </Grid.ColumnDefinitions>

              <!-- Page Up button -->
              <Button Grid.Column="2" Command="{x:Static ScrollBar.PageUpCommand}"
                        Style="{DynamicResource NakedButtonStyle}" Padding="2,5"
                        Visibility="{Binding ElementName=PART_VerticalScrollBar, Path=Visibility}">
                <Path Style="{StaticResource UpArrowStyle}"/>
              </Button>

              <!-- Page Down button -->
              <Button Grid.Column="2" Grid.Row="1" Command="{x:Static ScrollBar.PageDownCommand}"
                        Style="{DynamicResource NakedButtonStyle}" Padding="2,5"
                        Visibility="{Binding ElementName=PART_VerticalScrollBar, Path=Visibility}">
                <Path Style="{StaticResource DownArrowStyle}"/>
              </Button>

              <!-- Page Left button -->
              <Button Grid.Column="0" Grid.Row="1" Command="{x:Static ScrollBar.PageLeftCommand}"
                        Style="{DynamicResource NakedButtonStyle}" Padding="5,2"
                        Visibility="{Binding ElementName=PART_HorizontalScrollBar, Path=Visibility}">
                <Path Style="{StaticResource LeftArrowStyle}"/>
              </Button>

              <!-- Page Right button -->
              <Button Grid.Column="1" Grid.Row="1" Command="{x:Static ScrollBar.PageRightCommand}"
                        Style="{DynamicResource NakedButtonStyle}" Padding="5,2"
                        Visibility="{Binding ElementName=PART_HorizontalScrollBar, Path=Visibility}">
                <Path Style="{StaticResource RightArrowStyle}"/>
              </Button>

            </Grid>
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

</ResourceDictionary>